home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Moof / Goodies / HyperCard Goodies / HyperCard Dev. ToolKit / Serial & MacinTalk XCMDs / recvPort.p < prev    next >
Text File  |  1987-07-15  |  1KB  |  69 lines

  1. {$R-}
  2.  
  3. (*
  4.     recvSPort(port number) -- Return a character from the serial port.
  5.  
  6.     To compile and link this file using Macintosh Programmer's Workshop,
  7.  
  8.     pascal -w recvPort.p
  9.     link -m ENTRYPOINT -o HyperCommands -rt XFCN=1 -sn Main=recvSPort recvPort.p.o "{MPW}"Libraries:interface.o
  10.     
  11. *)
  12.  
  13. {$S recvSPort }     { Segment name must be the same as the command name. }
  14.  
  15. unit DummyUnit;
  16.  
  17. interface
  18.  
  19. uses MemTypes, QuickDraw, OSIntf, HyperXCmd;
  20.  
  21. procedure EntryPoint(paramPtr: XCmdPtr);
  22.     
  23. implementation
  24.  
  25. type
  26.  
  27. Str31 = String[31];
  28.  
  29. procedure recvSPort(paramPtr: XCmdPtr); forward;
  30.  
  31. procedure EntryPoint(paramPtr: XCmdPtr);
  32.  
  33.     begin
  34.         recvSPort(paramPtr);
  35.     end;
  36.  
  37. procedure recvSPort(paramPtr: XCmdPtr);
  38.  
  39.     var portNumber: integer;
  40.         inPort: integer;
  41.         str: Str255;
  42.         l: longInt;
  43.  
  44.     {$I XCmdGlue.inc}
  45.  
  46.     procedure Fail(errMsg: Str255); { set theResult and quit }
  47.         begin
  48.             paramPtr^.returnValue := PasToZero(errMsg);
  49.             exit(recvSPort);
  50.         end;
  51.  
  52.     begin
  53.         if paramPtr^.paramCount <> 1 then Fail('parameter count is not 1');
  54.  
  55.         ZeroToPas(paramPtr^.params[1]^,str);        { First parameter is port number. }
  56.         portNumber := StrToNum(str);
  57.         if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
  58.  
  59.         if portNumber = 1 then inPort := -6
  60.         else inPort := -8;
  61.         l := 1;
  62.         str[0] := chr(1);
  63.         if FSRead(inPort,l,Ptr(ord4(@str)+1)) <> noErr then Fail('FSRead failed');
  64.         if l <> 1 then str[0] := chr(0);
  65.         paramPtr^.returnValue := PasToZero(str);
  66.     end;
  67.  
  68. end.
  69.